﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;



using System.Diagnostics;
using Share.Data;

namespace Share
{
    public class ComboBox_Client:VMComboBox
    {
        /// <summary>
        /// Hiển thị dòng "Tất cả"
        /// </summary>

        public ComboBox_Client()
        {
            this.Loaded += new System.Windows.RoutedEventHandler(ComboBox_Unit_Loaded);
            if (Style == null)
                Style = new Style(typeof(ComboBox), (Style)Application.Current.Resources[typeof(ComboBox)]);
        }
        public bool IsOnlyShowAticedItem { get; set; }
        public bool IsOnlyShowAgreeRegisterItem { get; set; }
        Controls.ComboBoxHelper.ComboBoxFilterSupport<Client> _comboboxfiltersupport = null;
        void ComboBox_Unit_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            if (CanLoadData() == false)
                return;
            using (var dc = ShareDataCache.GetDataClientDataContext())
            {
                Client[] data = null;
                if (IsShowItemAll)
                {
                    var temp = dc.Clients.Where(c => c.IsDeleted == false).ToList();
                        temp.Insert(0, Client.ClientAll);
                    data = temp.ToArray();
                }
                else
                    data = dc.Clients.Where(c => c.IsDeleted == false).ToArray();

                if (IsOnlyShowAgreeRegisterItem == true)
                {
                    data = data.Where(c => c.IsAgreeRegister == true || c.ClientId == 0).ToArray();
                }
                if (IsOnlyShowAticedItem == true)
                {
                    data = data.Where(c => c.IsActive == true || c.ClientId == 0).ToArray();
                }
                this.SelectedValuePath = "ClientId";
                this.DisplayMemberPath = "ComputerName";
                if (_comboboxfiltersupport == null)
                {
                    _comboboxfiltersupport =
                        new Controls.ComboBoxHelper.ComboBoxFilterSupport<Client>(this,
                         data, u => u.ComputerName, null, "ComputerName",
                         Controls.ComboBoxHelper.Enum_ComboBoxFilterType.Contain);
                }
                else _comboboxfiltersupport.Source = data;
            }
        }
    }
   

}
